# key = "index" return key
def filter_keys(_list, conditions, key=""):
    _l = []
    if isinstance(conditions, dict):
        for index, item in enumerate(_list):
            for i in conditions:
                if not isinstance(conditions[i], dict):
                    if item[i] == conditions[i]:
                        if key == "":
                            _l.append(item)
                        else:
                            if key == "index":
                                _l.append(index)
                            else:
                                _l.append(item[key])
                else:
                    _c = conditions[i]
                    for __key in _c:
                        if __key == "<>":
                            if not item[i] == _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
                        elif __key == "<":
                            if item[i] < _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
                        elif __key == ">":
                            if item[i] > _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
                        elif __key == "<=":
                            if item[i] <= _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
                        elif __key == ">=":
                            if item[i] >= _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
                        else:
                            if item[i] == _c[__key]:
                                if key == "":
                                    _l.append(item)
                                else:
                                    if key == "index":
                                        _l.append(index)
                                    else:
                                        _l.append(item[key])
    else:
        def _(client, condition):
            for _key in condition:
                if not isinstance(condition[_key], dict):
                    return client[_key] == condition[_key]
                else:
                    _c = condition[_key]
                    for __key in _c:
                        if __key == "<>":
                            return not client[_key] == _c[__key]
                        elif __key == "<":
                            return client[_key] < _c[__key]
                        elif __key == ">":
                            return client[_key] > _c[__key]
                        elif __key == "<=":
                            return client[_key] <= _c[__key]
                        elif __key == ">=":
                            return client[_key] >= _c[__key]
                        else:
                            return client[_key] == _c[__key]

        __l = []
        for index, _client in enumerate(_list):
            __client = _client.copy()
            __client['conditions'] = []
            for condition in conditions:
                __client['conditions'].append(_(_client, condition))
            __l.append(__client)
        for index, _client in enumerate(__l):
            if False not in _client['conditions']:
                del _client['conditions']
                if key == "":
                    _l.append(_client)
                else:
                    if key == "index":
                        _l.append(index)
                    else:
                        _l.append(_client[key])
    return _l

test_data = [
    {"id": 1, "pid": 0, "title": "test"},
    {"id": 2, "pid": 1, "title": "test"},
    {"id": 3, "pid": 2, "title": "test"},
    {"id": 4, "pid": 2, "title": "test"},
    {"id": 5, "pid": 2, "title": "test"},
    {"id": 6, "pid": 0, "title": "test"},
    {"id": 7, "pid": 0, "title": "test"},
    {"id": 8, "pid": 0, "title": "test"},
    {"id": 9, "pid": 0, "title": "test"},
    {"id": 10, "pid": 0, "title": "test"},
]


print ('单条件筛选')
# filter list筛选
for x in filter_keys(test_data, {"id": {">": 3}}):
    print(x)


print ('多条件复合筛选')
# filter list筛选
for x in filter_keys(test_data, [{"id": {">": 3}},{"pid":0}]):
    print(x)